package com.atguigu.cloud.controller;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Collect;
import com.atguigu.cloud.sevice.Impl.CollectServiceImpl;
import com.atguigu.cloud.tool.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.controller
 * @className: collectcontrollor
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:22
 * @version: 1.0
 */
@RestController
@Tag(name = "收藏表", description = "收藏表增删改")
public class Collectcontrollor {
    @Resource
    CollectServiceImpl collectService;


    //增加收藏
    @PostMapping(value = "/collect/add")
    @Operation(summary = "添加收藏", description = "添加收藏")
    public ResultData<String> addcollect(@RequestBody Collect collect){
        System.out.println(collect.toString());
        int i = collectService.add(collect);
        return ResultData.success("成功插入记录，返回值："+i);
    }
    //删除收藏
    @DeleteMapping(value = "/collect/del/{id}")
    @Operation(summary = "删除收藏", description = "删除收藏")
    public ResultData<Integer> deletecollect(@PathVariable("id") Integer id) {
        Integer i=collectService.delete(id);
        return ResultData.success(i);
    }

    //修改收藏
    @PutMapping(value = "/collect/update")
    @Operation(summary = "修改收藏", description = "修改收藏")
    public ResultData<String> updatecollect(@RequestBody Collect collect){
        int i = collectService.update(collect);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    //查询收藏
    @GetMapping(value = "/collect/get/{id}")
    @Operation(summary = "查询收藏", description = "查询收藏")
    public ResultData<Collect> getById(@PathVariable("id") Integer id){
        Collect collect=collectService.getById(id);
        return ResultData.success(collect);
    }

    //查询所有收藏
    @GetMapping(value = "/collect/getall")
    @Operation(summary = "查询所有收藏", description = "查询所有收藏")
    public ResultData<List<Collect>> getAll(){
        return ResultData.success(collectService.getAll());
    }

}
